<template>
  <div class="playervideoDisplay">
    <!-- 加载中 -->
    <div class="spinner" v-if="!datas">
      <van-loading type="spinner" size="30px" />
    </div>
    <div class="playertop" @click.stop="Mouse">
      <video
        v-if="MV.url"
        ref="video"
        :src="MV.url"
        autoplay
        @timeupdate="ontimeupdateFun"
      ></video>
      <div class="empty" v-if="flat">
        <van-empty
          v-if="monitoring == null"
          image="error"
          description="视频跑丢啦~~"
        />
      </div>

      <!-- 退出按钮 -->
      <div
        class="quit iconfont icon-fanhui"
        @click="previous"
        v-show="isMouse"
      ></div>
      <!-- 分享 -->
      <div
        class="share iconfont icon-gengduo-shuxiang"
        v-show="isMouse"
        @click="showShare = true"
      >
        <van-share-sheet
          v-model="showShare"
          :options="options"
          @select="onSelect"
          @click="cancel"
        />
      </div>
      <!-- 播放暂停 -->
      <div class="play" @click="togglePlay" v-show="isMouse">
        <span v-show="iconPlay" class="iconfont icon-24gl-pause2"></span>
        <span v-show="!iconPlay" class="iconfont icon-24gl-play"></span>
      </div>
      <!-- 进度条 -->
      <div class="progress" v-show="isMouse">
        <van-slider
          v-model="currentRate"
          :button-size="10"
          :active-color="'#ff0000'"
          @input="onChange"
        />
        <div class="timeLeft">{{ timeLeft }}</div>
        <div class="timeRight">{{ timeRight }}</div>
        <span class="screen iconfont icon-quanping1"></span>
      </div>
    </div>
    <!--  -->
    <div class="intro" v-if="datas">
      <div class="iost" @click="changes(1)" :class="{ con: 1 == num }">
        简介
      </div>
      <div
        class="iost"
        @click="changes(2)"
        :class="{ con: 2 == num }"
        v-if="commentsnum"
      >
        评论<span>{{ commentsnum }}</span>
      </div>
    </div>
    <!--  -->
    <!-- <div class="gisr" v-if="datas"></div> -->
    <!-- 简介 -->
    <div class="synopsis" v-show="num == 1" v-if="datas">
      <div class="next">
        <div class="top">
          <div class="img">
            <img src="../assets/8b.png" />
          </div>
          <p>{{ datas.title }}</p>
        </div>
        <div class="bottom">
          <div class="onet">
            <span>{{ datas.categories[0].category_name }}-</span>
            <span>{{ datas.categories[0].sub.category_name }}</span>
          </div>
          <div class="onet">06-21</div>
          <div class="onet"><span>13.6w</span> 次播放</div>
        </div>
      </div>
      <!--  -->
      <div class="like">
        <ul>
          <li>
            <div class="iconfont icon-dianzan"></div>
            <div class="ie">{{ datas.count.count_like }}</div>
          </li>
          <li>
            <div class="iconfont icon-shoucang"></div>
            <div class="ie">{{ datas.count.count_collect }}</div>
          </li>
          <li>
            <div class="iconfont icon-share-s"></div>
            <div class="ie">{{ datas.count.count_share }}</div>
          </li>
        </ul>
      </div>
      <!--  -->
      <div class="graduate">
        <ul>
          <li v-for="item in datas.tags" :key="item.id">{{ item.name }}</li>
        </ul>
      </div>
      <!-- 制作人 -->
      <div class="producer" v-if="datas.team.length > 0">
        <div class="box">制作人</div>
        <div class="inventor">
          <ul>
            <li v-for="item in datas.team" :key="item.id">
              <div class="img">
                <img :src="item.userinfo.avatar" alt="" />
              </div>
              <div class="author">
                <div class="left">
                  <span class="one">{{ item.userinfo.username }}</span>
                  <span class="two">{{ item.userinfo.occupation }}</span>
                </div>
                <div class="rigth">关注</div>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <div class="acquaintance">
        <p class="p">相似视频</p>
        <div class="list" v-for="item in lists" :key="item.id">
          <ul>
            <router-link tag="li" :to="'/VideoDisplay?id=' + item.id">
              <div class="img">
                <img :src="item.cover" />
              </div>
              <div class="lists">
                <p>{{ item.title }}</p>
                <div class="two">
                  <div class="amount">
                    播放量
                    <span>{{ item.count.count_view | playCountNum }} - </span>
                  </div>
                  <div class="likes">
                    喜欢 <span>{{ item.count.count_like | playCountNum }}</span>
                  </div>
                </div>
                <div class="names">
                  <div class="imgs" v-if="item.author.userinfo.avatar">
                    <img :src="item.author.userinfo.avatar" alt="" />
                  </div>
                  <div class="name">
                    {{ item.author.userinfo.username }}
                  </div>
                </div>
              </div>
            </router-link>
          </ul>
        </div>
      </div>
    </div>
    <!-- 评论 -->
    <div class="discuss" v-show="num == 2">
      <ul>
        <li v-for="item in commentslist" :key="item.id">
          <div class="img">
            <img :src="item.userInfo.avatar" alt="" />
          </div>
          <div class="list">
            <div class="one">
              <span>{{ item.userInfo.username }}</span>
              <div class="iconfont icon-gengduo-shuxiang"></div>
            </div>
            <p>{{ item.content }}</p>
            <div class="inferior">
              <div class="times">07-14</div>
              <div class="give">
                <div class="iconfont icon-pinglun"></div>
                <div class="iconfont icon-dianzan">
                  {{ item.count_approve }}
                </div>
              </div>
            </div>
          </div>
        </li>
      </ul>
    </div>
    <!-- 分享 -->
    <div class="cancel" v-if="showShare" @click="showShare = false"></div>
  </div>
</template>

<script>
import { Toast } from "vant";
import { getarticle, getresult, getcomments } from "../api/home";
export default {
  data() {
    return {
      num: 1,
      MV: "",
      cancel: true,
      lists: "",
      datas: "",
      list: ["毕业", "校园", "青春", "回忆", "情怀", "vivo", "毕业"],
      iconPlay: false,
      isMouse: false, // 鼠标移上移出
      showShare: false,
      timer: null,
      timeLeft: 0, //滑块左边时间
      timeRight: 0, //滑块右边时间
      currentRate: 0, //小播放器进度条
      monitoring: null, //监控
      commentslist: "",
      commentsnum: "",
      flat: false,
      monitor: null, //监视跳转id
      options: [
        [
          { name: "微信", icon: "wechat" },
          { name: "朋友圈", icon: "wechat-moments" },
          { name: "微博", icon: "weibo" },
          { name: "QQ", icon: "qq" },
        ],
        [
          { name: "复制链接", icon: "link" },
          { name: "分享海报", icon: "poster" },
          { name: "二维码", icon: "qrcode" },
          { name: "小程序码", icon: "weapp-qrcode" },
        ],
      ],
    };
  },
  methods: {
    //点击跳转
    changes(key) {
      this.num = key;
    },
    // 延时器
    Mouse() {
      this.isMouse = true;
      console.log(this.isMouse);
      this.timer = setTimeout(() => {
        this.isMouse = false;
        console.log(this.isMouse);
      }, 4000);
    },
    //分享
    onSelect(option) {
      Toast(option.name);
      this.showShare = false;
    },
    // 返回上一页
    previous() {
      this.$router.go(-1);
    },
    //视频文章详情
    getarticleFun() {
      let articleId = this.$route.query.id;
      this.monitor = articleId;
      console.log(this.monitor, "id1");
      getarticle({ articleId: articleId }).then((data) => {
        // console.log(data, "视频文章详情");
        this.datas = data.data;
        // console.log(this.datas, "制作人");
        this.MV = data.data.video.content.progressive[0];
        // console.log(this.MV)
      });
    },
    //视频文章评论
    getgetcomments() {
      let resource_id = this.$route.query.id;
      // console.log(resource_id, "id2");
      getcomments({ resource_id: resource_id, page: 1 }).then((data) => {
        // console.log(data, "视频文章评论");
        this.commentslist = data.data.list;
        this.commentsnum = data.data.total;
      });
    },
    //搜索结果列表
    getresultFun() {
      // let kw = this.$route.query.kw;
      // console.log(kw, "kw");
      getresult({}).then((data) => {
        // console.log(data, "搜索结果");
        this.lists = data.data.list;
        // console.log(this.lists, "111");
      });
    },
    //视频播放
    togglePlay() {
      if (this.iconPlay) {
        this.$refs.video.play(); //播放
        console.log("播放");
      } else {
        this.$refs.video.pause(); //暂停
        clearTimeout(this.timer);
        this.timer = null;
        console.log("暂停");
      }
      this.iconPlay = !this.iconPlay;
    },
    //  --进度条
    ontimeupdateFun() {
      this.iconPlay = false;
      // currentTime	设置或返回音频中的当前播放位置（以秒计）
      // duration	返回当前音频的长度（以秒计）
      let currentTime = this.$refs.video.currentTime; //实时歌曲时间
      let duration = this.$refs.video.duration; //获取歌曲总时长
      this.monitoring = this.$refs.video.paused; //监控视频播放时常
      // console.log(this.$refs.video.paused, "00000");

      currentTime >= 60
        ? (this.timeLeft =
            Math.floor(currentTime / 60) +
            ":" +
            (Math.floor(currentTime % 60) < 10
              ? "0" + Math.floor(currentTime % 60)
              : Math.floor(currentTime % 60)))
        : (this.timeLeft =
            currentTime <= 10
              ? "0:0" + Math.floor(currentTime)
              : "0:" + Math.floor(currentTime)); //实时秒数

      duration >= 60
        ? (this.timeRight =
            Math.floor(duration / 60) +
            ":" +
            (Math.floor(duration % 60) < 10
              ? "0" + Math.floor(duration % 60)
              : Math.floor(duration % 60)))
        : (this.timeRight = "0:" + Math.floor(duration)); //总秒数

      // 计算播放时间进度条
      this.currentRate = (currentTime / duration) * 100;
    },
    // 进度条拖动事件
    onChange(value) {
      // console.log("当前值为", value);
      this.$refs.video.currentTime = this.$refs.video.duration * (value / 100);
    },
  },
  mounted() {
    this.getarticleFun();
    this.getresultFun();
    this.getgetcomments();
    setTimeout(() => {
      this.flat = true;
      console.log("6秒");
    }, 6000);
  },
  //过滤器
  filters: {
    playCountNum(value) {
      //123 0000
      if (value < 10000) {
        return value;
      }
      let w = value > 10000 ? value / 10000 : value; //万计算
      let y = w > 10000 ? parseInt(w / 10000) + "亿" : parseInt(w) + "万"; //亿计算
      return y;
    },
  },
  //侦听器
  watch: {
    monitor: function (newvalue, oldvalue) {
      console.log(newvalue, "新值");
      console.log(oldvalue, "旧值");
    },
  },
};
</script>

<style lang="less" >
.playervideoDisplay {
  width: 100%;
  position: absolute;
  z-index: 100;
  background-color: #fff;
  .spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  .playertop {
    width: 100%;
    height: 32%;
    position: relative;
    .empty {
      position: absolute;
      top: 0px;
      left: 0px;
      width: 100%;
      .van-empty {
        width: 100%;
        // z-index: 999;
        padding: 0px;
        background-color: #fff;
      }
    }

    .quit {
      position: absolute;
      top: 15px;
      left: 20px;
      font-size: 20px;
      color: rgb(196, 196, 196);
    }
    .share {
      position: absolute;
      top: 15px;
      right: 30px;
      font-size: 20px;
      color: rgb(196, 196, 196);
    }
    video {
      width: 100%;
      height: 100%;
      background-color: #202020;
    }
    .play {
      position: absolute;
      top: 43%;
      left: 46%;
      .iconfont {
        font-size: 30px;
        color: rgb(196, 196, 196);
      }
    }
    // 进度条
    .progress {
      width: 70%;
      margin: 0px auto;
      margin-left: 20px;
      position: absolute;
      bottom: 18px;
      left: 20px;
      .timeLeft,
      .timeRight {
        position: absolute;
        top: -6px;
        font-size: 12px;
        color: rgb(196, 196, 196);
        transform: scale(0.8);
      }
      .timeLeft {
        left: -29px;
      }
      .timeRight {
        right: -34px;
      }
      .screen {
        position: absolute;
        top: -8px;
        right: -57px;
        font-size: 16px;
        color: rgb(196, 196, 196);
      }
    }
  }
  .intro {
    width: 100%;
    height: 28px;
    line-height: 28px;
    display: flex;
    justify-content: space-around;
    border-bottom: 2px solid #e4e4e4;
    .iost {
      font-size: 13px;
      span {
        font-weight: 400;
        font-size: 12px;
        color: #eb766c;
        margin-left: 5px;
      }
    }
    .con {
      font-weight: 600;
      position: relative;
      &::after {
        position: absolute;
        left: 0px;
        bottom: 0px;
        content: "";
        display: inline-block;
        width: 25px;
        height: 4px;
        background: #e22f1c;
        border-radius: 3px;
      }
    }
  }
  // 简介
  .synopsis {
    .next {
      // width: 100%;
      display: flex;
      flex-direction: column;
      padding: 17px 15px 17px 15px;
      .top {
        display: flex;
        margin-bottom: 16px;
        .img {
          width: 18px;
          height: 18px;
          margin-right: 4px;
          img {
            width: 18px;
            height: 18px;
            border-radius: 50%;
          }
        }
        p {
          height: 18px;
          line-height: 18px;
          font-size: 18px;
          color: #202020;
          font-weight: 600;
          display: -webkit-box; /*将对象转为弹性盒模型展示*/
          -webkit-box-orient: vertical; /*设置弹性盒模型子元素的排列方式*/
          -webkit-line-clamp: 1; /*限制文本行数*/
          overflow: hidden; /*超出隐藏*/
        }
      }
      .bottom {
        display: flex;
        height: 12px;
        .onet {
          height: 12px;
          line-height: 12px;
          font-size: 12px;
          color: #b4b4b4;
          margin-right: 13px;
        }
      }
    }
    .like {
      width: 100%;
      height: 65px;
      ul {
        width: 100%;
        height: 65px;
        display: flex;
        justify-content: space-around;
        li {
          width: 25px;
          display: flex;
          flex-direction: column;
          .iconfont {
            font-size: 18px;
            margin: 0px auto;
            margin-bottom: 6px;
          }
          .ie {
            font-size: 12px;
            text-align: center;
          }
        }
      }
    }
    .graduate {
      // width: 100%;
      height: 48px;
      line-height: 48px;
      overflow-x: scroll;
      ul {
        //   width: 100%;
        padding-left: 5px;
        display: flex;
        // height: 48px;
        line-height: 48px;
        // border-bottom: 2px solid #fbfbfb;
        // border-top: 2px solid #fbfbfb;
        li {
          // 不压缩  flex-shrink: 0;
          flex-shrink: 0;
          margin: auto 4px;
          height: 20px;
          line-height: 20px;
          font-size: 12px;
          color: #888888;
          padding: 2px 10px 2px 10px;
          border-radius: 5px;
          background-color: #f9f9f9;
        }
      }
    }
    .box {
      height: 15px;
      line-height: 15px;
      font-size: 15px;
      margin: 17px 0px 15px 15px;
    }
    .inventor {
      // height: 60px;
      overflow-x: scroll;
      ul {
        margin-left: 15px;
        display: flex;
        // height: 63px;
        li {
          margin-top: 3px;
          flex-shrink: 0;
          margin-right: 13px;
          width: 210px;
          display: flex;
          height: 57px;
          border-radius: 5px;
          // border: 1px solid black;
          box-shadow: 0px 0px 3px 1px #f4f0f0;
          .img {
            width: 40px;
            height: 40px;
            margin: auto 10px;
            img {
              border: 1px solid #c8bfbf;
              width: 40px;
              height: 40px;
              border-radius: 50%;
            }
          }
          .author {
            display: flex;
            justify-content: space-between;
            flex: 1;
            .left {
              display: flex;
              flex-direction: column;
              .one {
                margin-top: 8px;
                height: 20px;
                width: 2em;
                overflow: hidden;
                line-height: 20px;
                font-size: 14px;
              }
              .two {
                height: 20px;
                line-height: 20px;
                font-size: 12px;
                color: #acacac;
              }
            }
            .rigth {
              height: 22px;
              line-height: 22px;
              background-color: #fdedeb;
              color: #e85345;
              font-size: 13px;
              padding: 2px 16px 2px 16px;
              margin-right: 15px;
              margin-top: 15px;
              border-radius: 64px;
            }
          }
        }
      }
    }
    .acquaintance {
      width: 100%;
      .p {
        margin: 15px 12px 0px 15px;
        font-size: 14px;
      }
      .list {
        width: 100%;
        ul {
          width: 100%;
          display: flex;
          flex-direction: column;
          li {
            display: flex;
            width: 100%;
            padding: 12px 0px 12px 0px;
            border-bottom: 1px solid #f3f3f3;
            .img {
              width: 125px;
              height: 70px;
              padding-left: 12px;
              img {
                width: 125px;
                height: 70px;
                border-radius: 5px;
              }
            }
            .lists {
              display: flex;
              flex-direction: column;
              margin-left: 10px;
              p {
                height: 33px;
                line-height: 33px;
                width: 100%;
                overflow: hidden;
                font-size: 13px;
                color: #1c1c1c;
              }
              .two {
                display: flex;
                height: 12px;
                font-size: 12px;
                line-height: 12px;
                color: #c0c0c0;
                overflow: hidden;
              }
              .names {
                color: #4a4a4a;
                font-size: 12px;
                height: 28px;
                line-height: 28px;
                display: flex;
                .imgs {
                  margin-top: 5px;
                  width: 16px;
                  height: 16px;
                  margin-right: 5px;
                  img {
                    height: 16px;
                    width: 16px;
                    border-radius: 50%;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  //评论
  .discuss {
    width: 100%;
    ul {
      display: flex;
      flex-direction: column;
      margin-top: 5px;
      width: 100%;
      li {
        display: flex;
        margin-top: 14px;
        width: 100%;
        .img {
          width: 33px;
          height: 33px;
          margin-left: 18px;
          margin-right: 12px;
          border-radius: 50%;
          border: 1px solid #f6f6f6;
          img {
            width: 33px;
            height: 33px;
            border-radius: 50%;
            background-color: #acacac;
          }
        }
        .list {
          display: flex;
          flex: 1;
          flex-direction: column;
          .one {
            display: flex;
            width: 100%;
            justify-content: space-between;
            span {
              height: 12px;
              margin-top: 3px;
              line-height: 12px;
              font-size: 12px;
              color: #7c7c7c;
            }
            .iconfont {
              margin-right: 18px;
            }
          }
          p {
            width: 90%;
            margin-top: 4px;
            line-height: 20px;
            font-size: 13px;
          }
          .inferior {
            display: flex;
            height: 14px;
            line-height: 14px;
            justify-content: space-between;
            margin-top: 10px;
            border-bottom: 2px solid #fafafa;
            padding-bottom: 10px;
            .times {
              color: #a0a0a0;
              font-size: 12px;
            }
            .give {
              display: flex;
              margin-right: 22px;
              .iconfont {
                margin-left: 18px;
                font-size: 14px;
              }
            }
          }
        }
      }
    }
  }
  // 分享遮罩层
  .cancel {
    z-index: 2053;
    position: fixed;
    height: 52%;
    width: 100%;
    // background-color: red;
    top: 0px;
    left: 0px;
  }
}
</style>